/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 attackable_object.cpp

	$Header: /heroes4/attackable_object.cpp $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "attackable_object.h"

#include "battlefield.h"
#include "creature_ability.h"
#include "spell.h"

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
void t_attackable_object::add_poison( int amount, t_combat_creature const& source )
{
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
void t_attackable_object::check_blocking()
{
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
t_attack_angle_list const& t_attackable_object::get_attack_angles( t_battlefield const& battlefield )
{
	return battlefield.get_data_cache().get_attack_angles( *battlefield.get_acting_creature(), 
														   *this);
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
bool t_attackable_object::has_ability( t_creature_ability ability ) const
{
	return ability == k_ability_mechanical;
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
bool t_attackable_object::is_blocking_attack() const
{
	return false;
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
bool t_attackable_object::is_giant() const
{
	return false;
}

bool t_attackable_object::is_gate() const
{
	return false;
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
int t_attackable_object::add_damage( int amount, t_combat_creature* source,
		                             bool check_luck, bool permanent,
									 t_combat_action_message const & damage_message )
{
	int limit = get_total_hits() - m_new_damage;

	if (limit < 0)
		limit = 0;
	if (amount > limit)
		amount = limit;
	m_new_damage += amount;

	if ( !m_new_damage_message.is_displayable() || m_new_damage_message.get_priority() <= damage_message.get_priority() )
	{
		m_new_damage_message = damage_message;
	}

	return amount;
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
bool t_attackable_object::begin_panic( t_combat_creature const& attacker )
{
	return false;
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
bool t_attackable_object::can_retaliate( t_combat_creature const& attacker, bool ranged, 
										 int turns ) const
{
	return false;
}

// -----------------------------------------------------------------------------
// return true if creature can take actions
// -----------------------------------------------------------------------------
bool t_attackable_object::is_awake() const
{
	return is_alive() && !is_active( k_spell_blind ) 
		   && !is_active( k_spell_frozen )
	       && !is_active( k_spell_stun );
}

// -----------------------------------------------------------------------------
// t_attackable_object's version of on_battlefield_destruction()
// -----------------------------------------------------------------------------
void t_attackable_object::on_battlefield_destruction_attackable_object()
{
	m_new_damage_message.clear();
}


// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
void t_attackable_object::preload_flinch( t_combat_creature const& attacker )
{
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
void t_attackable_object::flinch( t_combat_creature const& attacker, t_combat_action_message const & message )
{
}

// ----------------------------------------------------------------------
// object which can be attacked
// ----------------------------------------------------------------------
bool t_attackable_object::check_guardian_robe()
{
	return false;
}
